<?php
session_start();
require_once("../config/include.inc.php");
require_once("../class/Common_Function.php");

//访问权限验证
$userRole = $_SESSION['user_role'];
if($userRole == 1 ){
	//管理员
}else{
	if($userRole > 0){
		$url = "../index.php?loginError=2";//没权限
	}else{
		$url = "../index.php?loginError=3";//没登录
	}	
	echo "<script language='javascript' type='text/javascript'>";
	echo "window.location.href='$url'";
	echo "</script>";
}

$show_strAdd = 0;

//获取form值
$currentSiteName = "";
$currentSite = $_POST["currentSite"];	
$currentId = "";
$doFlag = $_POST["doFlag"];	
if($doFlag == "add"){
	$date_added = $_POST["date_added"];	
	$customers_name = $_POST["customers_name"];	
	$reviews_rating = $_POST["reviews_rating"];	
	$reviews_text = $_POST["reviews_text"];	
	$products_id = $_POST["products_id"];		
	if($date_added =="" || $customers_name == ""
	    || $reviews_rating == ""  
	    || $reviews_text == "" 
		){
		$strAdd = "**************************************";
		$strAdd = $strAdd."<br>";
		$strAdd = $strAdd."Error! 部分字段为空<br>";
		$strAdd = $strAdd."ProductID: ".$products_id."<br>";
		$strAdd = $strAdd."Date: ".$date_added."<br>";
		$strAdd = $strAdd."Customer: ".$customers_name."<br>";
		$strAdd = $strAdd."☆☆☆☆☆:".$reviews_rating."<br>";
		$strAdd = $strAdd."Reviews:".$reviews_text."<br>";
		$strAdd = $strAdd."**************************************";			
	}else{
		$strAdd = "**************************************";
		$strAdd = $strAdd."<br>";
		$strAdd = $strAdd."评论添加成功！<br>";
		$strAdd = $strAdd."Date: ".$date_added."<br>";
	    $strAdd = $strAdd."ProductID: ".$products_id."<br>";
		$strAdd = $strAdd."Customer: ".$customers_name."<br>";
		$strAdd = $strAdd."☆☆☆☆☆:".$reviews_rating."<br>";
		$strAdd = $strAdd."Reviews:".$reviews_text."<br>";
		$strAdd = $strAdd."**************************************";
		
		if($currentSite == "H"){//hiteclaser
			//获取当前最大reviews_id
			$sql = "select max(reviews_id) as reviews_id from  reviews";
			$result = $db_H->Execute($sql);
			if(!$result->EOF){
				$currentId = $result->fields['reviews_id'];	
			}
			if($currentId != ""){
				$currentId = $currentId + 1;
			}else{
				$currentId = 1;
			}
			//table:reviews ,customers_id=1, status=1
			$sql = "insert into reviews 
	                (reviews_id,products_id,customers_id,customers_name,reviews_rating,date_added,status) 
	                values ($currentId,$products_id,1,'$customers_name',$reviews_rating,'$date_added',1)
	                 ";
	        $db_H->Execute($sql);
	        //table:reviews_description, languages_id = 1
	        $sql = "insert into reviews_description 
					(reviews_id,languages_id,reviews_text) 
					values ($currentId,1,'$reviews_text') ";
	        $db_H->Execute($sql);	
		}else if($currentSite == "LJ"){//lucklaser.jp
			//获取当前最大reviews_id
			$sql = "select max(reviews_id) as reviews_id from  reviews";
			$result = $db_LJ->Execute($sql);
			if(!$result->EOF){
				$currentId = $result->fields['reviews_id'];	
			}
			if($currentId != ""){
				$currentId = $currentId + 1;
			}else{
				$currentId = 1;
			}
			//table:reviews ,customers_id=1, status=1
			$sql = "insert into reviews 
	                (reviews_id,products_id,customers_id,customers_name,reviews_rating,date_added,status) 
	                values ($currentId,$products_id,1,'$customers_name',$reviews_rating,'$date_added',1)
	                 ";
	        $db_LJ->Execute($sql);
	        //table:reviews_description, languages_id = 1
	        $sql = "insert into reviews_description 
					(reviews_id,languages_id,reviews_text) 
					values ($currentId,1,'$reviews_text') ";
	        $db_LJ->Execute($sql);
	
		}else if($currentSite == "LK"){//lucklaser-kr
			//获取当前最大reviews_id
			$sql = "select max(reviews_id) as reviews_id from  reviews";
			$result = $db_LK->Execute($sql);
			if(!$result->EOF){
				$currentId = $result->fields['reviews_id'];	
			}
			if($currentId != ""){
				$currentId = $currentId + 1;
			}else{
				$currentId = 1;
			}
			//table:reviews ,customers_id=1, status=1
			$sql = "insert into reviews 
	                (reviews_id,products_id,customers_id,customers_name,reviews_rating,date_added,status) 
	                values ($currentId,$products_id,1,'$customers_name',$reviews_rating,'$date_added',1)
	                 ";
	        $db_LK->Execute($sql);
	        //table:reviews_description, languages_id = 1
	        $sql = "insert into reviews_description 
					(reviews_id,languages_id,reviews_text) 
					values ($currentId,1,'$reviews_text') ";
	        $db_LK->Execute($sql);

		}else if($currentSite == "LD"){
			//获取当前最大reviews_id
			$sql = "select max(reviews_id) as reviews_id from  reviews";
			$result = $db_LD->Execute($sql);
			if(!$result->EOF){
				$currentId = $result->fields['reviews_id'];	
			}
			if($currentId != ""){
				$currentId = $currentId + 1;
			}else{
				$currentId = 1;
			}
			//table:reviews ,customers_id=1, status=1
			$sql = "insert into reviews 
	                (reviews_id,products_id,customers_id,customers_name,reviews_rating,date_added,status) 
	                values ($currentId,$products_id,1,'$customers_name',$reviews_rating,'$date_added',1)
	                 ";
	        $db_LD->Execute($sql);
	        //table:reviews_description, languages_id = 1
	        $sql = "insert into reviews_description 
					(reviews_id,languages_id,reviews_text) 
					values ($currentId,1,'$reviews_text') ";
	        $db_LD->Execute($sql);			
		}else if($currentSite == "L"){ //lucklaser
			//获取当前最大reviews_id
			$sql = "select max(reviews_id) as reviews_id from  reviews";
			$result = $db_L->Execute($sql);
			if(!$result->EOF){
				$currentId = $result->fields['reviews_id'];	
			}
			if($currentId != ""){
				$currentId = $currentId + 1;
			}else{
				$currentId = 1;
			}
			//table:reviews ,customers_id=1, status=1
			$sql = "insert into reviews 
	                (reviews_id,products_id,customers_id,customers_name,reviews_rating,date_added,status) 
	                values ($currentId,$products_id,1,'$customers_name',$reviews_rating,'$date_added',1)
	                 ";
	        $db_L->Execute($sql);
	        //table:reviews_description, languages_id = 1
	        $sql = "insert into reviews_description 
					(reviews_id,languages_id,reviews_text) 
					values ($currentId,1,'$reviews_text') ";
	        $db_L->Execute($sql);	
	    }else if($currentSite == "K"){
			//获取当前最大reviews_id
			$sql = "select max(reviews_id) as reviews_id from  reviews";
			$result = $db_K->Execute($sql);
			if(!$result->EOF){
				$currentId = $result->fields['reviews_id'];	
			}
			if($currentId != ""){
				$currentId = $currentId + 1;
			}else{
				$currentId = 1;
			}
			//table:reviews ,customers_id=1, status=1
			$sql = "insert into reviews 
	                (reviews_id,products_id,customers_id,customers_name,reviews_rating,date_added,status) 
	                values ($currentId,$products_id,1,'$customers_name',$reviews_rating,'$date_added',1)
	                 ";
	        $db_K->Execute($sql);
	        //table:reviews_description, languages_id = 1
	        $sql = "insert into reviews_description 
					(reviews_id,languages_id,reviews_text) 
					values ($currentId,1,'$reviews_text') ";
	        $db_K->Execute($sql);	
		}else if($currentSite == "D"){
			//获取当前最大reviews_id
			$sql = "select max(reviews_id) as reviews_id from  reviews";
			$result = $db_D->Execute($sql);
			if(!$result->EOF){
				$currentId = $result->fields['reviews_id'];	
			}
			if($currentId != ""){
				$currentId = $currentId + 1;
			}else{
				$currentId = 1;
			}
			//table:reviews ,customers_id=1, status=1
			$sql = "insert into reviews 
	                (reviews_id,products_id,customers_id,customers_name,reviews_rating,date_added,status) 
	                values ($currentId,$products_id,1,'$customers_name',$reviews_rating,'$date_added',1)
	                 ";
	        $db_D->Execute($sql);
	        //table:reviews_description, languages_id = 1
	        $sql = "insert into reviews_description 
					(reviews_id,languages_id,reviews_text) 
					values ($currentId,1,'$reviews_text') ";
	        $db_D->Execute($sql);	
		}else if($currentSite == "S"){
			//获取当前最大reviews_id
			$sql = "select max(reviews_id) as reviews_id from  reviews";
			$result = $db_S->Execute($sql);
			if(!$result->EOF){
				$currentId = $result->fields['reviews_id'];	
			}
			if($currentId != ""){
				$currentId = $currentId + 1;
			}else{
				$currentId = 1;
			}
			//table:reviews ,customers_id=1, status=1
			$sql = "insert into reviews 
	                (reviews_id,products_id,customers_id,customers_name,reviews_rating,date_added,status) 
	                values ($currentId,$products_id,1,'$customers_name',$reviews_rating,'$date_added',1)
	                 ";
	        $db_S->Execute($sql);
	        //table:reviews_description, languages_id = 1
	        $sql = "insert into reviews_description 
					(reviews_id,languages_id,reviews_text) 
					values ($currentId,1,'$reviews_text') ";
	        $db_S->Execute($sql);
		}else if($currentSite == "C"){
			//获取当前最大reviews_id
			$sql = "select max(reviews_id) as reviews_id from  reviews";
			$result = $db_C->Execute($sql);
			if(!$result->EOF){
				$currentId = $result->fields['reviews_id'];	
			}
			if($currentId != ""){
				$currentId = $currentId + 1;
			}else{
				$currentId = 1;
			}
			//table:reviews ,customers_id=1, status=1
			$sql = "insert into reviews 
	                (reviews_id,products_id,customers_id,customers_name,reviews_rating,date_added,status) 
	                values ($currentId,$products_id,1,'$customers_name',$reviews_rating,'$date_added',1)
	                 ";
	        $db_C->Execute($sql);
	        //table:reviews_description, languages_id = 1
	        $sql = "insert into reviews_description 
					(reviews_id,languages_id,reviews_text) 
					values ($currentId,1,'$reviews_text') ";
	        $db_C->Execute($sql);
		}else if($currentSite == "CJ"){
			//获取当前最大reviews_id
			$sql = "select max(reviews_id) as reviews_id from  reviews";
			$result = $db_CJ->Execute($sql);
			if(!$result->EOF){
				$currentId = $result->fields['reviews_id'];	
			}
			if($currentId != ""){
				$currentId = $currentId + 1;
			}else{
				$currentId = 1;
			}
			//table:reviews ,customers_id=1, status=1
			$sql = "insert into reviews 
	                (reviews_id,products_id,customers_id,customers_name,reviews_rating,date_added,status) 
	                values ($currentId,$products_id,1,'$customers_name',$reviews_rating,'$date_added',1)
	                 ";
	        $db_CJ->Execute($sql);
	        //table:reviews_description, languages_id = 1
	        $sql = "insert into reviews_description 
					(reviews_id,languages_id,reviews_text) 
					values ($currentId,1,'$reviews_text') ";
	        $db_CJ->Execute($sql);
		}else if($currentSite == "CA"){ //canetalaser
			//获取当前最大reviews_id
			$sql = "select max(reviews_id) as reviews_id from  reviews";
			$result = $db_CA->Execute($sql);
			if(!$result->EOF){
				$currentId = $result->fields['reviews_id'];	
			}
			if($currentId != ""){
				$currentId = $currentId + 1;
			}else{
				$currentId = 1;
			}
			//table:reviews ,customers_id=1, status=1
			$sql = "insert into reviews 
	                (reviews_id,products_id,customers_id,customers_name,reviews_rating,date_added,status) 
	                values ($currentId,$products_id,1,'$customers_name',$reviews_rating,'$date_added',1)
	                 ";
	        $db_CA->Execute($sql);
	        //table:reviews_description, languages_id = 1
	        $sql = "insert into reviews_description 
					(reviews_id,languages_id,reviews_text) 
					values ($currentId,1,'$reviews_text') ";
	        $db_CA->Execute($sql);	
		}
	}
	//echo $strAdd;	
	$show_strAdd = 1;

}		
if($currentSite == "H"){
	$currentSiteName = "Hiteclaser";	
}else if($currentSite == "LJ"){
	$currentSiteName = "lucklaser.jp";
}else if($currentSite == "LK"){
	$currentSiteName = "kr.lucklaser";
}else if($currentSite == "LD"){
	$currentSiteName = "Laser-door";
}else if($currentSite == "L"){
	$currentSiteName = "Lucklaser";
}else if($currentSite == "K"){
	$currentSiteName = "Kennbikyou";
}else if($currentSite == "D"){
	$currentSiteName = "Dmicroscope";
}else if($currentSite == "S"){
	$currentSiteName = "Spycamhidden";
}else if($currentSite == "C"){
	$currentSiteName = "Civillaser";
}else if($currentSite == "CJ"){
	$currentSiteName = "jp.Civillaser";
}else if($currentSite == "CA"){
	$currentSiteName = "Canetalaser";
}
	




?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!--Begin:head-->
<? $pageTitle = "添加Review"; ?>
<?php include("../head.php"); ?>
<!--End:head-->


<body>
<?php include("../topMenu.php"); ?>

<?php
if($show_strAdd == 1){
	echo "<div><br>".$strAdd."<br></div>";
}
?>

<form name="inputForm" action="../review/reviewInput.php" method="post">
<div id="container" >	
<div class="grayTable">	
<h4>
<?php echo $currentSiteName;?>添加Review:
</h4>
<table >
	<tr>
		<td align="right">产品ID:</td>
		<td align="left"><input type="text" name="products_id" id="products_id" size=5></td>
	</tr>			
	<tr>
		<td align="right">客户名字:</td>
		<td align="left"><input type="text" name="customers_name" id="customers_name" size=20></td>
	</tr>
	<tr>
		<td align="right">好评等级:</td>
		<td align="left"><input type="text" name="reviews_rating" id="reviews_rating" value="5" size=5></td>
	</tr>
	<tr>
		<td align="right">评论时间:</td>
		<td align="left"><input type="text" name="date_added" id="date_added" value='<?php echo date("Y-m-d H:i:s");?>' > </td>
	</tr>
	<tr>
		<td align="right">评论内容:</td>
		<td align="left">
			<textarea cols="50" rows="5" id="reviews_text" name="reviews_text"></textarea>
			<br>(先ERROR提交，得到Reviews内容)
		</td>
	</tr>	
	<tr>
		<td colspan=2 align="right"><input type="submit" value="添加评论"></td>
	</tr>					
</table>	



</div>

<br><br>

</div><!--end container -->

<input type="hidden" name="doFlag" id="doFlag" value="add">
<input type="hidden" name="currentSite" id="currentSite" value="<?php echo $currentSite; ?>">
</form>
</body>




</html>

<script>

</script>

